package com.xzz.mq.consumer;

import com.xzz.service.IPayOrderService;
import io.netty.util.CharsetUtil;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(
        consumerGroup = "service-pay-outtime-consumer",
        topic="topic-paytimeout",
        selectorExpression="tag-paytimeout",
        messageModel= MessageModel.BROADCASTING   //广播模式： 一个消息可以被多个人同时消费
)
public class PayOutTimeConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private IPayOrderService payOrderService;

    @Override
    public void onMessage(MessageExt message) {
        String orderNo = new String(message.getBody(), CharsetUtil.UTF_8);
        //支付超时关单
        payOrderService.closeOrder(orderNo);
    }
}